package com.wholesale;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.ViewFlipper;

import com.wholesale.datas.WebServiceClient;
import com.wholesale.utils.Constants;

public class MoreLayout extends LinearLayout{   
	private ViewFlipper viewFlipper ;
	private Context context ;
	private View baseView ;
	private ListView bodyList ;
	private Button leftButton ;
	private Button rightButton ;
	private TextView headView ;
	
	//  构造函数  
	public MoreLayout(Context context,final ViewFlipper viewFlipper){
		super(context);
		this.viewFlipper = viewFlipper ;
		this.context = context ;
		//加载需要的属性，加载方法一的子Layout  
		baseView = ((Activity) getContext()).getLayoutInflater().inflate(R.layout.common, this);  
		bodyList = (ListView)baseView.findViewById(R.id.bodyList);
		leftButton = (Button)baseView.findViewById(R.id.leftBtn);
		leftButton.setVisibility(View.INVISIBLE);
		rightButton = (Button)baseView.findViewById(R.id.rightBtn);
		rightButton.setVisibility(View.INVISIBLE);
		headView = (TextView)baseView.findViewById(R.id.title);
		headView.setText("More");
		SimpleAdapter listItemAdapter = new SimpleAdapter(
				context, WebServiceClient.getMoreData(),// 数据源
				R.layout.moreitem,// ListItem的XML实现
				new String[] { "text" }, new int[] {
						R.id.item_text});
        bodyList.setAdapter(listItemAdapter);
        bodyList.setSelector(R.drawable.more_list_bg);
        // item 单击事件
        bodyList.setOnItemClickListener(moreClieckListener);
        
	}
	//more ListView 点击事件
    OnItemClickListener moreClieckListener = new OnItemClickListener() {
    	public void onItemClick(AdapterView<?> arg0, View arg1,
				int arg2, long arg3) {
			switch (arg2) {
			case 0:
				if(Constants.userInfo == null){
					UserLoginLayout userLoginLayout = new UserLoginLayout(context, viewFlipper);
					viewFlipper.addView(userLoginLayout);
					viewFlipper.showNext();
				}else{
					MyAccountLayout myAccountLayout = new MyAccountLayout(context, viewFlipper);
					viewFlipper.addView(myAccountLayout);
					viewFlipper.showNext();
				}
				break;
			case 1:
				SearchLayout searchLayout = new SearchLayout(context, viewFlipper);
				viewFlipper.addView(searchLayout);
				viewFlipper.showNext();
				break;
			case 2:
				HistoryLayout historyLayout = new HistoryLayout(context, viewFlipper);
				viewFlipper.addView(historyLayout);
				viewFlipper.showNext();
				break;
			case 3:
				HelpLayout helpLayout = new HelpLayout(context, viewFlipper);
				viewFlipper.addView(helpLayout);
				viewFlipper.showNext();
				break;
			case 4:
				if(Constants.userInfo == null){
					UserLoginLayout userLoginLayout = new UserLoginLayout(context, viewFlipper);
					viewFlipper.addView(userLoginLayout);
					viewFlipper.showNext();
				}else{
					FeedBackLayout feedBackLayout = new FeedBackLayout(context, viewFlipper);
					viewFlipper.addView(feedBackLayout);
					viewFlipper.showNext();
				}
				break;
			case 5:
				AboutLayout aboutLayout = new AboutLayout(context, viewFlipper);
				viewFlipper.addView(aboutLayout);
				viewFlipper.showNext();
				break;
			default:
				break;
			}
		}
    };
}
